using System;
using System.Xml;

using Google.Apps.Provisioning.Utilities;

namespace Google.Apps.Provisioning.Actions
{
    /// <summary>
    /// Implements steps specific to a CreateUser API call.
    /// </summary>
    internal class CreateUserAction : BaseProvisioningAction
    {
        private GoogleUser user;

        public CreateUserAction( GoogleUser user ) : base( 
            "Google.Apps.Provisioning.XmlTemplates.CreateUser.xml",
            "https://www.google.com/a/services/v1.0/Create/Account/Email" )
        {
            this.user = user;
        }

        public override void ProcessRequestXml( XmlDocument doc, XmlNamespaceManager ns )
        {
            XmlNode createNode = doc.SelectSingleNode( "hs:rest/hs:CreateSection", ns );

            createNode.SelectSingleNode( "hs:firstName", ns ).InnerText = user.FirstName;
            createNode.SelectSingleNode( "hs:lastName", ns ).InnerText  = user.LastName;
            createNode.SelectSingleNode( "hs:password", ns ).InnerText  = user.Password;
            createNode.SelectSingleNode( "hs:userName", ns ).InnerText  = user.UserName;
            createNode.SelectSingleNode( "hs:quota", ns ).InnerText     = user.Quota.ToString();;
        }
    }
}
